[3.9] gh-108310: Fix CVE-2023-40217: Check for & avoid the ssl pre-close flaw (#108320)
authorŁukasz Langa <lukasz@langa.pl>
Tue, 22 Aug 2023 17:57:10 +0000 (19:57 +0200)
committerArnaud Rebillout <arnaudr@debian.org>
Tue, 14 Apr 2026 04:38:32 +0000 (11:38 +0700)
commit1f6b9d4264785282d5f51a4a9959d8304292faa1
treeeabdf6d5bf7ec4a2044d05742dbd49c2a26562ac
parentb9a4c0b9b5012928fe3bc456b6257a6961c24be9
[3.9] gh-108310: Fix CVE-2023-40217: Check for & avoid the ssl pre-close flaw (#108320)

gh-108310: Fix CVE-2023-40217: Check for & avoid the ssl pre-close flaw

Instances of `ssl.SSLSocket` were vulnerable to a bypass of the TLS handshake
and included protections (like certificate verification) and treating sent
unencrypted data as if it were post-handshake TLS encrypted data.

The vulnerability is caused when a socket is connected, data is sent by the
malicious peer and stored in a buffer, and then the malicious peer closes the
socket within a small timing window before the other peers’ TLS handshake can
begin. After this sequence of events the closed socket will not immediately
attempt a TLS handshake due to not being connected but will also allow the
buffered data to be read as if a successful TLS handshake had occurred.

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Gbp-Pq: Name 0016-3.9-gh-108310-Fix-CVE-2023-40217-Check-for-avoid-the.patch
Lib/ssl.py
Lib/test/test_ssl.py